import Vue from 'vue'
import Vuex from 'vuex'
import { loginPost } from '@/api/user'
import { setToken, getToken } from '@/utils/storage'
Vue.use(Vuex)
import user from './user'
export default new Vuex.Store({
  state: {
    token:getToken()
  },
  getters: {
  },
  mutations: {
    changelogin(state,token){
      state.token=token
      setToken(token)
    }
  },
  actions: {
    async asynclogin ({ commit }, rouleform) {
      const res = await loginPost(rouleform)
      console.log(res);
      commit('changelogin',res.data.token)
    }
  },
  modules: {
    logout(){
      this.$route.push('user/login')
    },
    user
  }
})
